package com.xuchaotong.utils.bean;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;

import java.util.Date;

import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

/**
 * @author EASON.TONG
 * @create 2021/06/11
 **/
@Slf4j
public class BeanUtilsTest {


    @Test
    public void testCopy() {
        UserSource source = new UserSource();
        source.setId(10L);
        source.setName("Kity");
        source.setCreateTime(new Date());
        UserBaseInfo userBaseInfo = new UserBaseInfo();
        userBaseInfo.setNickName("Tom猫");
        userBaseInfo.setRealName("Tomsssss");
        source.setUserBaseInfo(userBaseInfo);

        UserTarget target = new UserTarget();
        target.setAge(20);
        UserBaseInfo userBaseInfo1 = new UserBaseInfo();
        userBaseInfo1.setRealName("Jerry鼠");
        target.setUserBaseInfo(userBaseInfo1);


        UserTarget obj = BeanUtils.merge(source, target, UserTarget.class);
        UserBaseInfo userBaseInfoMerge = BeanUtils.merge(userBaseInfo, userBaseInfo1, UserBaseInfo.class);
        obj.setUserBaseInfo(userBaseInfoMerge);

//        BeanUtils.copy(source,target,true);

        System.out.println(JSON.toJSONString(obj));
    }

    @Test
    public void testMerge() {
        Princess princess1 = new Princess();
        princess1.setName("Jenny");
        princess1.setAge(20);
        princess1.setCar("BMW");

        Princess princess2 = new Princess();
        princess2.setName("Kity");
        princess2.setAge(21);
        princess2.setHouse("big house");

        Princess princess = BeanUtils.merge(princess1, princess2, Princess.class);

        System.out.println(JSON.toJSONString(princess));
    }
}
